import {useCreateModal} from "@/hooks"
import EditModal from './edit-modal.vue'
import {ClientDelete} from "@/api/client"
import {Badge} from 'ant-design-vue'
import {createVNode} from 'vue'
import {OsName} from "@/views/terminal/utils"

export const columns = [ // 进程策略
    {
        title: '终端序列号',
        dataIndex: 'clienthash',
        slots:{
            customRender: 'clienthash'
        },
        slotsType: 'component',
        slotsFunc: (record) => createVNode(
            "a",
            {
                href:`#/terminal/info/${record.clienthash}`,
                text:record.clienthash
            }
            )
    },
    {
        title: '系统类型',
        dataIndex: 'os',
        slots:{
            customRender: 'os'
        },
        slotsType: 'format',
        slotsFunc: (os)=>(OsName[os])
    },
    {
        title: '最后登录IP',
        dataIndex: 'lastip',
        slots:{
            customRender: 'lastip'
        },
        slotsType: 'format',
        slotsFunc: (ip)=>{
            return null==ip?'- · - · - · -':ip
        }
    },
    {
        title: '状态',
        dataIndex: 'status',
        sorter: (a,b)=>a.status-b.status,
        sortOrder: "descend",
        sortDirections: "descend",
        slots: {
            customRender: 'status'
        },
        slotsType: 'component',
        slotsFunc: (record) => createVNode(Badge, {
            status: record.status == 1 ? 'processing' : 'default',
            text: record.status == 1 ? '在线' : '离线'
        })
    },
    {
        title: '终端别名',
        dataIndex: 'clientname',
    },
    {
        title: '终端版本',
        dataIndex: 'clientversion',
    },
    {
        title: '操作',
        dataIndex: 'action',
        width: 200,
        slots: {
            customRender: 'action'
        },
        actions: [
            {
                type: 'popconfirm', // 控制类型，默认为a,可选： select | button | text
                key: 'fileid', // 删除的依据，如果需要根据多个字段删除，则字段之间以英文逗号分隔开，例如： id, name
                text: '删除',
                permission: 'client:delete',
                props: {
                    type: 'danger'
                },
                func: async ({record}, callback) => {
                    await ClientDelete({id: record.clienthash})
                    callback()
                },
            },
            {
                type: 'button', // 控制类型，默认为a,可选： select | button | text
                key: 'fileid', // 删除的依据，如果需要根据多个字段删除，则字段之间以英文逗号分隔开，例如： id, name
                text: '编辑',
                permission: 'client:update',
                props: {
                    type: 'warning'
                },
                func: ({record}, callback) => useCreateModal(EditModal, {
                    fields: record,
                    callback
                }),
            }
        ]
    },
]
